//
//  JRHttpRequestConstants.h
//  
//
//  Created by dingjiarui on 2021/7/26.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface JRHttpRequestConstants : NSObject

/// 单列类
+ (instancetype)constants;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;


/** ============= 上传 下载 文件请求 ============= */

/// 创建队列
/// @param opId 队列标识
/// @param maxCount 最大线程
- (nullable NSOperationQueue *)createOperationQueue:(NSString *)opId maxCount:(NSInteger)maxCount;

/**
 *  @author djr
 *
 *  获取线程 若不存在opId的队列，则自动创建 线程数量默认为10的队列，所有线程处理完毕后队列自动销毁
 *  也可以使用createOperationQueue:maxCount:创建队列，若创建队列不使用，则不会释放，直到调用cancelAllOperations:才能释放
 *
 *  @param key  线程标记
 *  @param opId 队列标记 可为nil 则使用全局队列
 *
 */
- (nullable NSOperation *)operationForKey:(NSString *)key opId:(NSString *)opId;
/** 添加线程到队列 */
- (void)addOperation:(NSOperation *)op key:(NSString *)key opId:(NSString *)opId;
/** 清除线程 */
- (void)cancelOperationWithKey:(NSString *)key withOpId:(NSString *)opId completion:(void (^ _Nullable)(NSOperation *operation))completion;
/** 清除某个队列的线程 */
- (void)cancelAllOperationsWithOpId:(NSString *)opId completion:(void (^)(NSOperation *operation))completion;
/** 清除所有队列的线程 */
- (void)cancelAllOperations:(void (^)(NSOperation *operation))completion;


/** ============= 网络请求 ============= */

/** 添加线程 */
- (void)addOperationRequest:(NSOperation *)op;
- (void)addOperationRequest:(NSOperation *)op key:(nullable NSString *)key;
- (void)addOperationRequest:(NSOperation *)op key:(nullable NSString *)key opId:(nullable NSString *)opId;


@end

NS_ASSUME_NONNULL_END
